<#compress>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>股票筛选</title>
<!--        <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">-->
        <link href="/bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet">
<!--        <link rel="stylesheet" type="text/css" media="screen" href="http://res.51so.info/ui.jqgrid-bootstrap.css"/>-->
        <link rel="stylesheet" type="text/css" media="screen" href="/plugs/jqgrid/ui.jqgrid-bootstrap.css"/>
        <style>
            /*.navbar-fixed-top {*/
            /*     !*position: fixed;*!*/
            /*    right: 0;*/
            /*    left: 0;*/
            /*    z-index: 1030;*/
            /*}*/

            div.header
            　　 {
                　　text-align: center;
            }

            #app span {
                margin-left: 10px;
            }
            html {
                /*overflow-x: hidden; */
                /*overflow-y: auto;*/
            }
        </style>
    </head>
    <body >
    <#include  "/pub/menu.ftl"/>
    <div class="row" style="margin-top: 60px;margin-bottom: 10px;">
        <div class="col-md-12" style="padding-left: 30px;">
            <form class="form-inline" onkeydown="if(event.keyCode==13){reloadStock(); return false;}">
                <div class="form-group">
                    <div class="input-group">
                        <div class="input-group-addon">$</div>
                        <input type="text" class="form-control" id="stockCode" placeholder="代码 / 股票名称" maxlength="6">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <select class="form-control" id="stockType" placeholder="市场">
                            <option value="">全部</option>
                            <option value="sz">深市</option>
                            <option value="sh">沪市</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <div class="input-group-addon">PB</div>
                        <input type="text" class="form-control" id="stockPb" placeholder="0.1-1(市净率>=0.1<=1)"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <select class="form-control" id="dyType" placeholder="股息类型">
                            <option value="dy">股息(动)</option>
                            <option value="dividend">股息(静)</option>
                            <option value="fiveYearDy">5年平均股息</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <select class="form-control" id="typeFilter" placeholder="类型筛选">
                            <option value="">所有股票</option>
                            <option value="typeFilter">非创业板、非科创板、非st</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="priceFilter" placeholder="3-10(价格>=3<=10)"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="maybeFilter" placeholder="3-10(盈亏比>=3%<=10%)"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="maybeProfitFilter" placeholder="70-100(盈利>=70%<=100%)"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="maybeLossFilter" placeholder="10-20(亏损>=10%<=20%)"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="adjustBackFilter" placeholder="10-20(回调>=10%<=20%)"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="totalMarketValueFilter" placeholder="80-300(总市值（亿）)"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="volReducedRatioFilter" placeholder="2-10(近期缩量倍数)"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="lowestVolFilter" placeholder="30，x天内出现地量"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="stockDy" placeholder="3-10(股息>=3<=10)"
                               maxlength="10">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <select id="industry" class="form-control" placeholder="中证分类">
                            <option value="">请选择所属行业</option>
                            <#list zzfl as text>
                                <option value="${text}">${text}</option>
                            </#list>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="thsIndustry" placeholder="同花顺行业">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="thsConcepts" placeholder="同花顺概念">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input type="text" class="form-control" id="mainBusiness" placeholder="同花顺主营业务">
                    </div>
                </div>
                <button type="button" class="btn btn-primary" id="search_btn">查询</button>
                <button type="button" class="btn btn-info" id="refresh_btn">重置</button>
                <button type="button" class="btn btn-warning" id="baseinfo_btn">基本信息</button>
                <button type="button" class="btn btn-warning" id="h2_bt">h2数据库</button>
                <button type="button" class="btn btn-warning" id="swagger_bt">swagger接口</button>


                <div class="btn-group">
                    <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown"
                            aria-haspopup="true" aria-expanded="false">
                        大盘分析 <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a  id="index_sh_bt">上证指数</a></li>
                        <li><a  id="index_sz_bt">深证指数</a></li>
                        <li><a  id="index_cyb_bt">创业板</a></li>
                        <li><a  id="index_kcb_bt">科创板</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a  id="updowns_bt">同花顺/涨跌分布</a></li>
                        <li><a  id="north_money_bt">东方财富/北向资金</a></li>
                    </ul>
                </div>

                <div class="btn-group">
                    <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown"
                            aria-haspopup="true" aria-expanded="false">
                        行业分析 <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a id="board_industry_top_btn">行业/概念/个股资金排行</a></li>
                        <li><a id="board_industry_btn">行业板块</a></li>
                        <li><a id="board_concept_btn">概念板块</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a id="industry_analyse_btn">行业分析</a></li>
                    </ul>
                </div>

                <!-- Single button -->
                <div class="btn-group">
                    <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown"
                            aria-haspopup="true" aria-expanded="false">
                        个股分析 <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="#" id="finance_report_btn">同花顺/财务报表</a></li>
                        <li><a href="#" id="study_report_btn">萝卜投研/券商研报</a></li>
                        <li><a href="#" id="dy_btn">历史分红</a></li>
                        <li><a href="#" id="roe_btn">历史净资产收益率</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#" id="his_btn">历史pb/pe/股价</a></li>
                        <li><a href="#" id="report_btn">历史财务报表</a></li>
                    </ul>
                </div>
                <button type="button" class="btn btn-warning" id="stockpricedaily_btn">k线图</button>
                <button type="button" class="btn btn-warning" id="update_current_page_max">更新日线数据</button>
                <button type="button" class="btn btn-warning" id="addcollect">添到收藏</button>
                <button type="button" class="btn btn-warning" id="mycollect">我的收藏</button>

            </form>
        </div>
    </div>
    <!-- jqGrid高度取决于 doResize 方法 -->
    <table id="jqGrid" style="height: 400px"></table>
    <div id="jqGridPager"></div>

    </body>
        <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
        <script src="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <!--<script src="/bootstrap/js/bootstrap.min.js"></script>-->
        <!--<script src="/plugs/jqgrid/grid.locale-cn.js"></script>-->
        <script src="https://cdn.bootcss.com/jqgrid/4.6.0/js/i18n/grid.locale-cn.js"></script>
<!--        <script src="http://res.51so.info/jquery.jqGrid.min.js"></script>-->
        <script src="/plugs/jqgrid/jquery.jqGrid.min.js"></script>
    </html>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#jqGrid").jqGrid({
                url: "/stockInfo/list",
                width: window.screen.availWidth - 20,
                autowidth: false,
                shrinkToFit: false,
                multiselect: true,//复选框
                rownumbers: true,
                loadtext: '正在加载数据请稍后...',
                mtype: "GET",
                styleUI: 'Bootstrap',
                datatype: "json",
                colNames: ['代码', '名称','行业', '总市值', '相关概念',
                    '营业收入','营收同比增长','净利润','净利同比增长','毛利率','报告期',
                    '分类', '市场', '价格', '昨收','52周最低','52周最高', '涨幅', '市盈率(动)', '市盈率(静)','市盈率(TTM)', '市净率', '每股净资产', '股息(动)', '上次分红','3年平均股息', '5年平均股息','最新ROE','3年平均ROE','5年平均ROE'],
                colModel: [

                    {label: 'code', name: 'code', width: 100},
                    {label: 'name', name: 'name', width: 150},
                    {label: 'industry', name: 'industry', width: 130},
                    {label: 'totalValue', name: 'totalValue', width: 80, align: 'right'},
                    {label: 'concepts', name: 'concepts', width: 400},

                    {label: 'totalIncome', name: 'totalIncome', width: 80, align: 'right'},
                    {label: 'incomeDiff', name: 'incomeDiff', width: 100, align: 'right'},
                    {label: 'totalProfits', name: 'totalProfits', width: 70, align: 'right'},
                    {label: 'profitsDiff', name: 'profitsDiff', width: 100, align: 'right'},
                    {label: 'mll', name: 'mll', width: 90, align: 'right'},
                    {label: 'report', name: 'report', width: 70, align: 'center'},
                    {label: 'stype', name: 'stype', width: 70},

                    {label: 'type', name: 'type', width: 40},
                    {label: 'price', name: 'price', width: 50, align: 'right'},
                    {label: 'yesterdayPrice', name: 'yesterdayPrice', width: 60, align: 'right'},
                    {label: 'low52w', name: 'low52w', width: 70, align: 'right'},
                    {label: 'high52w', name: 'high52w', width: 70, align: 'right'},

                    {label: 'fluctuate', name: 'fluctuate', width: 70, align: 'right'},
                    {label: 'ped', name: 'ped', width: 80, align: 'right'},
                    {label: 'pes', name: 'pes', width: 80, align: 'right'},
                    {label: 'pettm', name: 'pettm', width: 93, align: 'right'},
                    {label: 'pb', name: 'pb', width: 60, align: 'right'},


                    {label: 'bvps', name: 'bvps', width: 90, align: 'right'},
                    {label: 'dy', name: 'dy', width: 70, align: 'right'},
                    {label: 'dividend', name: 'dividend', width: 150, align: 'right', formatter:sdyFormat},
                    {label: 'threeYearDy', name: 'threeYearDy', width: 90, align: 'right'},
                    {label: 'fiveYearDy', name: 'fiveYearDy', width: 90, align: 'right'},
                    {label: 'roe', name: 'roe', width: 75, align: 'right'},
                    {label: 'threeYearRoe', name: 'threeYearRoe', width: 96, align: 'right'},
                    {label: 'fiveYearRoe', name: 'fiveYearRoe', width: 96, align: 'right'},


//                {label: 'sVersion', name: 'sVersion', width: 650}
                ],
                viewrecords: true,
                rowList: [10, 20, 30, 60,300,600,1000,2000,4000,6000],
                //height: '90%',
                height: '50px',
                rowNum: 10,
                pager: "#jqGridPager",
                gridComplete: function () {
                    var ids = $("#jqGrid").getDataIDs();
                    for (var i = 0; i < ids.length; i++) {
                        var rowData = $("#jqGrid").getRowData(ids[i]);
                        if (parseFloat(rowData.fluctuate) < 0) {
                            $("#jqGrid").find('#' + ids[i]).find("td:eq(8)").css("color", "#00FF00");
                        } else {
                            $("#jqGrid").find('#' + ids[i]).find("td:eq(8)").css("color", "#FF3300");
                        }
                        var incomeDiff=parseFloat(rowData.incomeDiff);
                        if ( incomeDiff < 0) {
                            $("#jqGrid").find('#' + ids[i]).find("td:eq(23)").css("color", "#00FF00");
                        } else if ( incomeDiff > 0) {
                            $("#jqGrid").find('#' + ids[i]).find("td:eq(23)").css("color", "#FF3300");
                        }
                        var profitsDiff=parseFloat(rowData.profitsDiff);
                        if ( profitsDiff< 0) {
                            $("#jqGrid").find('#' + ids[i]).find("td:eq(25)").css("color", "#00FF00");
                        } else if ( profitsDiff>0){
                            $("#jqGrid").find('#' + ids[i]).find("td:eq(25)").css("color", "#FF3300");
                        }
                        if (parseFloat(rowData.fiveYearDy) > 4) {
                            $("#jqGrid").find('#' + ids[i]).find("td:eq(18)").css("color", "#FF3300");
                        }
                    }
                },
                ondblClickRow: function (id) {
                    //双击行
                    /* var rowData = $("#jqGrid").getRowData(id);
                     window.open("/stock/his_dy/"+rowData.code);*/
                    var rowData = $("#jqGrid").getRowData(id);
                    window.open("/StockDailyPrice/" + rowData.code);
                }
            });
            //$("#jqGrid").jqGrid("setFrozenColumns");
            doResize();
        });
        var t = document.documentElement.clientWidth;
        window.onresize = function () {
            if (t != document.documentElement.clientWidth) {
                t = document.documentElement.clientWidth;
                doResize();
            }
        }

        function sdyFormat( cellvalue, options, rowObject ){
            if(cellvalue!=undefined){
                return cellvalue+'\t'+rowObject.dividendDate;
            }
            return '--';
        }

        function getPageSize() {
            var winW, winH;
            if (window.innerHeight) {// all except IE
                winW = window.innerWidth;
                winH = window.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
                winW = document.documentElement.clientWidth;
                winH = document.documentElement.clientHeight;
            } else if (document.body) { // other
                winW = document.body.clientWidth;
                winH = document.body.clientHeight;
            }  // for small pages with total size less then the viewport
            return {WinW: winW, WinH: winH};
        }

        function doResize() {
            var ss = getPageSize();
            $("#jqGrid")
                .jqGrid('setGridWidth', ss.WinW - 10)
                .jqGrid('setGridHeight', ss.WinH - 280);
                // .jqGrid('setGridHeight', ss.WinH - ss.WinH*0.45);
        }
        //刷新列表
        function reloadStock() {
            //此处可以添加对查询数据的合法验证
            var code = $("#stockCode").val();
            var type = $("#stockType").val();
            var pb = $("#stockPb").val();
            // var dy = $("#dyType").val() + "-" + $("#stockDy").val();
            var dy = "";
            var pb = $("#stockPb").val();
            var industry = $("#industry").val();
            var typeFilter = $("#typeFilter").val();
            var priceFilter = $("#priceFilter").val();
            var maybeFilter = $("#maybeFilter").val();
            var maybeProfitFilter = $("#maybeProfitFilter").val();
            var maybeLossFilter = $("#maybeLossFilter").val();
            var adjustBackFilter = $("#adjustBackFilter").val();
            var totalMarketValueFilter = $("#totalMarketValueFilter").val();
            var volReducedRatioFilter = $("#volReducedRatioFilter").val();
            var lowestVolFilter = $("#lowestVolFilter").val();
            var thsIndustry = $("#thsIndustry").val();
            var thsConcepts = $("#thsConcepts").val();
            var mainBusiness = $("#mainBusiness").val();
            var zzfl = $("#zzfl").val();
            $("#jqGrid").jqGrid('setGridParam', {
                datatype: 'json',
                postData: {'code': code,
                    'type': type,
                    'pb': pb,
                    'dy': dy,
                    'industry':industry,
                    'typeFilter':typeFilter,
                    'priceFilter':priceFilter,
                    'maybeFilter':maybeFilter,
                    'maybeProfitFilter':maybeProfitFilter,
                    'maybeLossFilter':maybeLossFilter,
                    'adjustBackFilter':adjustBackFilter,
                    'totalMarketValueFilter':totalMarketValueFilter,
                    'volReducedRatioFilter':volReducedRatioFilter,
                    'lowestVolFilter':lowestVolFilter,
                    'thsIndustry':thsIndustry,
                    'thsConcepts':thsConcepts,
                    'mainBusiness':mainBusiness},
                page: 1
            }).trigger("reloadGrid");
        }

        $("#search_btn").click(function () {
            reloadStock();
        });
        $("#refresh_btn").click(function () {
            $("#stockCode").val("");
            $("#stockType").val("");
            $("#stockPb").val("");
            $("#stockDy").val("");
            $("#industry").val("");
            reloadStock();
        });
        $("#dy_btn").click(function () {
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selrow');
            if (null == ids) {
                alert("请选择要查看的股票!");
                return;
            }
            var rowData = $("#jqGrid").jqGrid('getRowData', ids);
            window.open("/stock/his_dy/" + rowData.code);
        });
        $("#roe_btn").click(function () {
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selrow');
            if (null == ids) {
                alert("请选择要查看的股票!");
                return;
            }
            var rowData = $("#jqGrid").jqGrid('getRowData', ids);
            window.open("/stock/financial/" + rowData.code);
        });

        $("#his_btn").click(function () {
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selrow');
            if (null == ids) {
                alert("请选择要查看的股票!");
                return;
            }
            var rowData = $("#jqGrid").jqGrid('getRowData', ids);
            window.open("/stock/hisdata/" + rowData.code);
        });
        $("#report_btn").click(function () {
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selrow');
            if (null == ids) {
                alert("请选择要查看的股票!");
                return;
            }
            var rowData = $("#jqGrid").jqGrid('getRowData', ids);
            window.open("/stock/report/" + rowData.code);
        });
        $("#baseinfo_btn").click(function (){
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selrow');
            if (null == ids) {
                alert("请选择要查看的股票!");
                return;
            }
            var rowData = $("#jqGrid").jqGrid('getRowData', ids);
            window.open("/stockInfo/" + rowData.code);
        });
        $("#stockpricedaily_btn").click(function (){
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selrow');
            if (null == ids) {
                alert("请选择要查看的股票!");
                return;
            }
            var rowData = $("#jqGrid").jqGrid('getRowData', ids);
            window.open("/StockDailyPrice/" + rowData.code);
        });
        $("#updowns_bt").click(function (){
            window.open("http://q.10jqka.com.cn/");
        });
        $("#index_sh_bt").click(function (){
            window.open("/StockDailyIndex/SH000001");
        });
        $("#index_sz_bt").click(function (){
            window.open("/StockDailyIndex/SZ399001");
        });
        $("#index_cyb_bt").click(function (){
            window.open("/StockDailyIndex/SZ399006");
        });
        $("#index_kcb_bt").click(function (){
            window.open("/StockDailyIndex/SH000688");
        });
        $("#north_money_bt").click(function (){
            window.open("http://data.eastmoney.com/hsgt/index.html");
        });
        $("#h2_bt").click(function (){
            window.open("http://localhost:8888/h2-console");
        });
        $("#swagger_bt").click(function (){
            window.open("http://localhost:8888/swagger-ui.html?docExpansion=list");
        });
        $("#board_industry_top_btn").click(function (){
            window.open("http://data.10jqka.com.cn/funds/hyzjl/###");
        });
        $("#board_industry_btn").click(function (){
            window.open("http://q.10jqka.com.cn/thshy/");
        });
        $("#board_concept_btn").click(function (){
            window.open("http://q.10jqka.com.cn/gn/");
        });
        $("#industry_analyse_btn").click(function (){
            window.open("/stockIndustry/index");
        });
        $("#mycollect").click(function (){
            window.open("/stockCollect/index");
        });
        $("#addcollect").click(function (){
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selarrrow');
            if (ids.length==0) {
                alert("请选择要添加的股票!");
                return;
            }


            var allRows = []
            allRows = $("#jqGrid").getRowData();
            var rows = allRows.filter((x, i) => ids.indexOf(""+(i+1)+"")>=0);
            // debugger
            var codes = []
            var names = []
            for (let i = 0; i < rows.length; i++) {
                var code = rows[i].code;
                var name = rows[i].name;
                codes.push(code)
                names.push(name)
                console.log(code)
            }
            $.post("/stockCollect/addcollect", { codes: codes.join(","), names: names.join(",")},
                function(data){
                    console.log(data)
                    alert("股票已经添加到收藏完成: " + data);
                });

        });
        $("#finance_report_btn").click(function (){
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selrow');
            if (null == ids) {
                alert("请选择要查看的股票!");
                return;
            }
            var rowData = $("#jqGrid").jqGrid('getRowData', ids);
            window.open("http://stockpage.10jqka.com.cn/"+rowData.code+"/finance/#finance");
        });
        $("#study_report_btn").click(function (){
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selrow');
            if (null == ids) {
                alert("请选择要查看的股票!");
                return;
            }
            var rowData = $("#jqGrid").jqGrid('getRowData', ids);
            window.open("https://robo.datayes.com/v2/search?query="+rowData.name+"&type=EXTERNALREPORT");
        });

        $("#update_current_page_max").click(function (){
            // var ids1 = $("#jqGrid").getDataIDs();
            var ids = $("#jqGrid").jqGrid('getGridParam', 'selarrrow');
            if (ids.length==0) {
                alert("请选择要查看的股票!");
                return;
            }
            var rows = []
            rows = $("#jqGrid").getRowData();
            var codes = []
            for (let i = 0; i < rows.length; i++) {
                var code = rows[i].code;
                codes.push(code)
                console.log(code)
            }
            $.post("/stock/refreshCodeListDailyPriceToMax", { codes: codes.join(",") },
                function(data){
                    alert("价格数据更新完成: " + data);
                });

        });
    </script>
</#compress>
